package de.slothsoft.wasbinich.swingclient.res;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public final class Messages {

    private static final String BUNDLE_NAME = "de.slothsoft.wasbinich.swingclient.res.messages"; //$NON-NLS-1$

    private static Locale locale = Locale.getDefault();

    public static String getString(Enum<?> anEnum) {
	return getString(anEnum.getClass().getSimpleName() + "." + anEnum);
    }

    public static String getString(String key) {
	try {
	    return ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(key);
	} catch (MissingResourceException e) {
	    return '!' + key + '!';
	}
    }

    public static void setLocale(Locale locale) {
	Messages.locale = locale;
    }

    public static Locale getLocale() {
	return locale;
    }

    private Messages() {
	// hide class
    }

}
